package com.m3839.sdk.common;

import com.m3839.sdk.common.env.ApiConfigDev;
import com.m3839.sdk.common.env.ApiConfigOfficial;
import com.m3839.sdk.common.env.ApiConfigOnlineTest;
import com.m3839.sdk.common.env.IApiConfig;
import com.m3839.sdk.common.http.HttpDefaultManager;
import com.m3839.sdk.common.http.IHttpManager;

/**
 * @author ChenBaoyang
 * @description: GlobalManager 作为公共库需要全局处理的出口处
 * @date 2021/11/5 15:45
 */
public class GlobalManager {

    private IApiConfig config;

    private IHttpManager httpManager;

    private GlobalManager() {
    }

    private static class SingletonHolder {
        private static final GlobalManager INSTANCE = new GlobalManager();
    }

    /**
     * 返回GlobalManager对象
     */
    public static GlobalManager getInstance() {
        return SingletonHolder.INSTANCE;
    }

    public void init() {
        httpManager = HttpDefaultManager.getManager();
    }

    public void setApiTestMode() {
        config = new ApiConfigDev();
    }

    public void setApiOnlineTestMode() {
        config = new ApiConfigOnlineTest();
    }

    public void setApiOnlineOfficial() {
        config = new ApiConfigOfficial();
    }

    public IApiConfig getApiConfig() {
        return config;
    }

    public IHttpManager getHttpManager() {
        return httpManager;
    }
}
